package com.chengv.redismq.demo;

import cn.hutool.json.JSONUtil;
import com.chengv.redismq.annotation.RedisMQMessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DemoService {

    // --------------------------------------------------------------------------------------------------------广播模式
    @RedisMQMessageListener(topic = DemoMQTopicConstant.BROADCAST_MODE_DEMO, consumerGroup = "consumer_group_1")
    public void broadcastModeDemoConsumerGroup1(String id) {
        log.info("broadcastModeDemoConsumerGroup1 接收到 id=({}) 的消息", id);
    }

    @RedisMQMessageListener(topic = DemoMQTopicConstant.BROADCAST_MODE_DEMO, consumerGroup = "consumer_group_2")
    public void broadcastModeDemoConsumerGroup2(String id) {
        log.info("broadcastModeDemoConsumerGroup2 接收到 id=({}) 的消息", id);
    }

    // --------------------------------------------------------------------------------------------------------集群模式
    @RedisMQMessageListener(topic = DemoMQTopicConstant.CLUSTER_MODE_DEMO)
    public void clusterModeDemoConsumer1(DemoEntity demoEntity) {
        log.info("clusterModeDemoConsumer1 接收到 demoEntity=({}) 的消息", JSONUtil.toJsonStr(demoEntity));
    }

    @RedisMQMessageListener(topic = DemoMQTopicConstant.CLUSTER_MODE_DEMO)
    public void clusterModeDemoConsumer2(DemoEntity demoEntity) {
        log.info("clusterModeDemoConsumer2 接收到 demoEntity=({}) 的消息", JSONUtil.toJsonStr(demoEntity));
    }

    // --------------------------------------------------------------------------------------------------------延迟消息
    @RedisMQMessageListener(topic = DemoMQTopicConstant.DELAY_MESSAGE_DEMO)
    public void delayMessageDemo(String id) {
        log.info("delayMessageDemo 接收到 id=({}) 的消息", id);
    }
}
